package com.ghd.dataviz.core.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：ghd
 * @date ：Created in 2020-03-23 20:35
 * @description：
 * @modified By：
 * @version: $
 */
@Configuration
public class JacksonConfig {
    private static final ObjectMapper INSTANCE;

    static {
        INSTANCE = new ObjectMapper();
        INSTANCE.registerModule(new JavaTimeModule());
        INSTANCE.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        INSTANCE.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        INSTANCE.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    @Bean
    public ObjectMapper jsonConfig() {
        return INSTANCE;
    }

}
